﻿//PlazaException.cs
//Copyright (c) 2013 StockSharp LLC, all rights reserved.
//This code module is part of StockSharp library.
//This code is licensed under the GNU GENERAL PUBLIC LICENSE Version 3.
//See the file License.txt for the license details.
//More info on: http://stocksharp.com

namespace StockSharp.Plaza
{
	using System;
	using System.Runtime.InteropServices;

	using Ecng.Common;

	/// <summary>
	/// Исключение, содержащее код и описание ошибки, полученной от Plaza.
	/// </summary>
	public class PlazaException : ApplicationException
	{
		internal PlazaException(string message, COMException exception)
			: base(FormatErrorText(message, exception.ErrorCode, exception.GetErrorText()), exception)
		{
			ErrorCode = exception.ErrorCode;
		}

		internal PlazaException(int errorCode, string errorText)
			: base(FormatErrorText("Произошла ошибка.", errorCode, errorText))
		{
			ErrorCode = errorCode;
		}

		/// <summary>
		/// Код ошибки, которую прислала Plaza.
		/// </summary>
		public int ErrorCode { get; private set; }

		private static string FormatErrorText(string message, int errorCode, string errorText)
		{
			if (message.IsEmpty())
				throw new ArgumentNullException("message");

			return "{0} Код {1}, описание '{2}'.".Put(message, errorCode, errorText);
		}
	}
}